package LeetCode.month01.day23;

import java.util.Arrays;

public class No1052 {
    public static void main(String[] args) {
        System.out.println(maxSatisfied(new int[]{4,10,10}, new int[]{1,1,0}, 2));
    }
    public static int maxSatisfied(int[] customers, int[] grumpy, int minutes) {
        int len = customers.length;
        int sum = 0;
        int les = 0;
        int res = 0;
        for (int i = 0; i < len; i++) {
            if(grumpy[i]==0) sum+=customers[i];
        }
        for (int i = 0; i < len; i++) {
            if(i<minutes){
                if(grumpy[i]==1) les+=customers[i];
            }else{
                res=Math.max(res,les);
                if(grumpy[i]==1) les+=customers[i];
                if(grumpy[i-minutes]==1) les-=customers[i-minutes];
            }
        }
        return sum+Math.max(res,les);
    }
}
